import PageBase from "./pageBase";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Message extends PageBase {

    onLoad() {

    }

    start() {
        this.init();
    }

    private delay:number = 2;

    setData(text:string,delay:number) {
        this.delay = delay;

        let textLb:cc.Label = this.showNode.getChildByName("text").getComponent(cc.Label);
        textLb.string = text;
        //
        // textLb._forceUpdateRenderData();
    }

    protected init(): void {
        this.open();
    }

    open(): void {
        this.showNode.scale = 0.01;
        this.showNode.y -= 50;
        this.showNode.opacity = 0;
        cc.tween(this.showNode)
            .parallel(
                cc.tween(this.showNode).to(0.2, { scale: 1 }),
                cc.tween(this.showNode).by(0.2, { y: 50 }),
                cc.tween(this.showNode).to(0.2, { opacity: 255 }),
            )
            .by(this.delay, { y: 80 })
            .parallel(
                cc.tween(this.showNode).to(0.5, { opacity: 0 }),
                cc.tween(this.showNode).by(0.5, { y: 50 }),
            )
            .call(this.close.bind(this))
            .start();
    }

    close(): void {
        this.node.destroy();
    }

    onlyClose(): void {
        this.close();
    }



    update(dt) {

    }
}
